<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <title>易织染 - 新用户注册</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script type="text/javascript" src="./js/jquery-3.1.1.min.js"></script>
  <style type="text/css">
  	.container {
  		padding: 15px;
  	}

  	.btn-container {
  		padding-top: 10px;
  	}
  </style>
</head>
<body>
	<div class="container">
		<h1>在下方填写真实姓名：</h1>
		<input id="real-name" type="text" name="real-name" style="height:50px;width: 100%; font-size:22px;">
		<div class="btn-container">
			<button id="btn" onclick="register()" style="height:50px;width: 100%;font-size:25px;">发送给管理员审核</button>
		</div>
	</div>

<!-- 	<button onclick="getCode()">获取CODE</button>
	<h2 id="code">这里显示code</h2>
	<h2 id="state">这里显示state</h2> -->
	<h2 id="user-info"></h2>

<script type="text/javascript">
	function register(){// 新用户注册
		const code = $.request.queryString["code"];
		const qrscene = $.request.queryString["qrscene"];
		const realName = $("#real-name").val();

		if(!realName){
			alert('【真实姓名】必须输入！');
			return;
		}

		document.getElementById("btn").disabled = true;
		const url = `../../wxpadbe/wx/register`;
		const params = {"code":code,"qrscene":qrscene,"realName":realName};

	  $.ajax({
  		url : url,
      type : "POST",
      contentType: "application/json;charset=UTF-8",
      data:JSON.stringify(params),
      success : function(res) {
      	console.log('网页授权请求用户信息响应来的结果是：',res);
      	const userInfoString = JSON.stringify(res);

      	if(res.code !== 1){
      		alert(res.msg);
      		return
      	}

      	$(`#user-info`).html("已提交管理员审核，请耐心等待！");
      },
      error : function(e){
        console.log(e.status);
        console.log(e.responseText);
      }
	  })

	}

	$(function(){// 页面启动即执行
		//getCode();
	});


	function getCode(){// 获取参数 code 的值
		const code = $.request.queryString["code"];	
		const state = $.request.queryString["state"];	
		console.log(`code:${code},state:${state}`);
		$(`#code`).html(`code:${code}`);
		$(`#state`).html(`state:${state}`);

		const url = `https://www.xdfznh.club/wxpadbe/dev/getWebAuthorityUserInfo/${code}`;
	  $.ajax({
	      type : "GET",
	      contentType: "application/json;charset=UTF-8",
	      url : url,
	      success : function(res) {
	      	console.log('网页授权请求用户信息响应来的结果是：',res);
	      	const userInfoString = JSON.stringify(res);
	      	$(`#user-info`).html(userInfoString);
	      },
	      error : function(e){
	        console.log(e.status);
	        console.log(e.responseText);
	      }
	  })



	}


	//String openId = getOpenIdFromReqMap(map);
	$.request = (function () {
	  var apiMap = {}; 
	  function request(queryStr) { 
	      var api = {}; 
	      if (apiMap[queryStr]) { return apiMap[queryStr]; } 
	      api.queryString = (function () { 
	          var urlParams = {}; 
	          var e, 
	          d = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); }, 
	          q = queryStr.substring(queryStr.indexOf('?') + 1), 
	          r = /([^&=]+)=?([^&]*)/g; 
	          while (e = r.exec(q))     urlParams[d(e[1])] = d(e[2]);
	          return urlParams; 
	      })(); 
	      api.getUrl = function () { 
	          var url = queryStr.substring(0, queryStr.indexOf('?') + 1); 
	          for (var p in api.queryString) { url += p + '=' + api.queryString[p] + "&";        } 
	          if (url.lastIndexOf('&') == url.length - 1) { return url.substring(0, url.lastIndexOf('&')); } 
	          return url; 
	      } 
	      apiMap[queryStr] = api; 
	      return api; 
	  } 
	  $.extend(request, request(window.location.href)); 
	  return request; 
	})();




</script>
</body>
